#include "mapa.h"
#include <list>
#include <vector>
#include <cmath>
#include <iostream>

using namespace std;


Mapa::Mapa( unsigned int X, unsigned int Y)
{
	this->alto = X;
	this->ancho = Y;
		
	datos_ady d;
	d.tiempo = 1;
	d.restric = SIN_RESTRIC;
	
	vector<datos_ady> v(Y,d);
	ady_restringidas_v.resize(X,v);
	
}

Mapa::~Mapa()
{
	
}

	
void Mapa::establecerRestriccion(lectura_casilla* casilla, unsigned int restric){
	unsigned int x = casilla->x;
	unsigned int y = casilla->y;
	unsigned int t = casilla->tiempo;
	
	ady_restringidas_v[x][y].tiempo = t;
	ady_restringidas_v[x][y].restric = restric;		
}


unsigned int Mapa::Ancho() {
	return ancho;
}
	

unsigned int Mapa::Alto() {
	return alto;
}


unsigned int Mapa::direcciones(unsigned int x, unsigned int y){
	return (ady_restringidas_v[x][y]).restric;
}

unsigned int Mapa::tiempo(unsigned int x, unsigned int y) {
	return (ady_restringidas_v[x][y]).tiempo;
}

unsigned int Mapa::tiempo(unsigned int lc){
	return (ady_restringidas_v[lc / ancho][lc % ancho]).tiempo;
}

list<unsigned int> Mapa::adyacentes(unsigned int lc) {
	unsigned int x = lc / ancho;
	unsigned int y = lc % ancho;
	unsigned int r = (ady_restringidas_v[x][y]).restric;
	list<unsigned int> nodos_ady;
	
	if (x < alto-1 && (r & ABAJO))	nodos_ady.push_back((x+1)*ancho+y);
	if (x > 0 && (r & ARRIBA))	nodos_ady.push_back((x-1)*ancho+y);
	if (y < ancho-1 && (r & DERECHA))	nodos_ady.push_back(x*ancho+y+1);
	if (y > 0 && (r & IZQUIERDA))	nodos_ady.push_back(x*ancho+y-1);
		
	return nodos_ady;
}
